<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreatePayRecordRequest;
use App\Http\Requests\UpdatePayRecordRequest;
use App\Repositories\PayRecordRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class PayRecordController extends AppBaseController
{
    /** @var  PayRecordRepository */
    private $payRecordRepository;

    public function __construct(PayRecordRepository $payRecordRepo)
    {
        $this->payRecordRepository = $payRecordRepo;
    }

    /**
     * Display a listing of the PayRecord.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->payRecordRepository->pushCriteria(new RequestCriteria($request));
        $payRecords = $this->payRecordRepository->paginate(20);

        return view('pay_records.index')
            ->with('payRecords', $payRecords);
    }

    /**
     * Show the form for creating a new PayRecord.
     *
     * @return Response
     */
    public function create()
    {
        return view('pay_records.create');
    }

    /**
     * Store a newly created PayRecord in storage.
     *
     * @param CreatePayRecordRequest $request
     *
     * @return Response
     */
    public function store(CreatePayRecordRequest $request)
    {
        $input = $request->all();

        $payRecord = $this->payRecordRepository->create($input);

        Flash::success('Pay Record saved successfully.');

        return redirect(route('payRecords.index'));
    }

    /**
     * Display the specified PayRecord.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $payRecord = $this->payRecordRepository->findWithoutFail($id);

        if (empty($payRecord)) {
            Flash::error('Pay Record not found');

            return redirect(route('payRecords.index'));
        }

        return view('pay_records.show')->with('payRecord', $payRecord);
    }

    /**
     * Show the form for editing the specified PayRecord.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $payRecord = $this->payRecordRepository->findWithoutFail($id);

        if (empty($payRecord)) {
            Flash::error('Pay Record not found');

            return redirect(route('payRecords.index'));
        }

        return view('pay_records.edit')->with('payRecord', $payRecord);
    }

    /**
     * Update the specified PayRecord in storage.
     *
     * @param  int              $id
     * @param UpdatePayRecordRequest $request
     *
     * @return Response
     */
    public function update($id, UpdatePayRecordRequest $request)
    {
        $payRecord = $this->payRecordRepository->findWithoutFail($id);

        if (empty($payRecord)) {
            Flash::error('Pay Record not found');

            return redirect(route('payRecords.index'));
        }

        $payRecord = $this->payRecordRepository->update($request->all(), $id);

        Flash::success('Pay Record updated successfully.');

        return redirect(route('payRecords.index'));
    }

    /**
     * Remove the specified PayRecord from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $payRecord = $this->payRecordRepository->findWithoutFail($id);

        if (empty($payRecord)) {
            Flash::error('Pay Record not found');

            return redirect(route('payRecords.index'));
        }

        $this->payRecordRepository->delete($id);

        Flash::success('Pay Record deleted successfully.');

        return redirect(route('payRecords.index'));
    }
}
